package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    //统计各个职位的员工人数
    @Override
    public JobOption getEmpJobData() {

        //这里为什么要并最终将结果存储在一个List中返回呢？
        // 因为jobList, dataList需要的数据格式是一个List，List中存储的是多个Map集合，Map集合中存储的是职位和对应的员工人数。
        //Map中的String是Pos和num是字符串，这里既员工人数Integer和职位名称String的类型所以这里值类型用的是Object
        //Map中的存储形式是第一个map key是pos，值是教研主管， key是num 值是1 在这里有6个map集合一个集合中有两个键值对...
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JobOption(jobList, dataList);

    }

    //统计员工性别信息
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    //学员学历统计
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    //班级人数统计
    @Override
    public ClazzOption getStudentCountData() {
        List<Map<String, Object>> list = studentMapper.countStudentCountData();

        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clazz")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new ClazzOption(clazzList, dataList);
    }

}
